import utilAxios from '@/util/util-axios'

const mechanismApi = utilAxios.initBaseApi('common', 'mechanism')
const platformApi = utilAxios.initBaseApi('function', 'platform')

const queryParams = [
]

const pageConfig = {
    limit: 20
}

const tableConfig = {
    mechanismId: {
        type: 'customer'
    },
    platformId: {
        type: 'customer'
    }
}

const formConfig = {
    ...tableConfig
}

export async function init() {
    await initConfig()

    return {
        queryParams,
        tableConfig,
        pageConfig,
        formConfig
    }
}

async function initConfig() {
    let res = await mechanismApi.list({ limit: 999 })
    tableConfig.mechanismId.dictList = res.records.map(item => {
        return { name: item.name, val: item.id }
    })

    res = await platformApi.list({ limit: 999 })
    tableConfig.platformId.dictList = [
        { name: '实体机房', val: '-1' },
        ...res.records.map(item => {
            return { name: item.name, val: item.id }
        })
    ]
}
